/**! @file config_parser.h
 * Declare interfaces of this library.
 *
 *   @module : configparser
 *   @date   : 2012-11-11
 *   @author : NoImagination
 *   @mail   : yyk882002@gmail.com (Bug-report)
 *   @license: GPL v3
 */
#ifndef _CONFIG_PARSER_H_384546
#define _CONFIG_PARSER_H_384546

#define CONF_NAME_LEN 128   /**< Name length of config item */
#define CONF_VALUE_LEN 128  /**< Value length of config item */
#define MAX_LINE_CHAR 256   /**< Max length per line */
#define COMMENT_CHAR '#'    /**< Comment flag */
#define COMMENT_BLANK ' '   /**< */
#ifdef __linux__
#define PATH_SEPORATOR "/"
#elif _WIN32
#define PATH_SEPORATOR "\\"
#endif

struct tag_config;

/**! config item structure
 */
typedef struct tag_config
{
	char name[CONF_NAME_LEN];    /**< name */
	char value[CONF_VALUE_LEN];  /**< value */
	struct tag_config* next;     /**< next item pointer */
}CONF_ITEM,*LPCONF_ITEM;

/**! get version */
char* get_version();

/**! initialize a CONF_ITEM structure */
CONF_ITEM* init();

/**! Get err description
 * @err: errno returned out of other function
 */
char* get_error_string(int err);

/**! read all configure items from a file
  *  @ctx: config items list header
  *  @filename: config file name(full path)
  *  @return : 0-ok
  */
int read_config(CONF_ITEM* ctx,const char* filename);

/**! Get configure item value .
  *  @ctx: config items list header
  *  @name: config item name
  *  @return: config value
  */
char* get_config(CONF_ITEM* ctx,const char* name);

/**! Free all the items memory
  *  @ctx: config items list header
  *  @return:0 
  */
int deinit(CONF_ITEM* ctx);

/**! delete every 't' at head and tail of 'str'
  * @str: string to be trim
  * @ t: flag character
  * @return:0 means ok
  */
int trim(char* str,char t);

/**! delete every 't' at head of 'str'
  * @str: string to be trim
  * @ t: flag character
  * @return:0 means ok
  */
int trim_l(char* str,char t);

/**! Delete every 't' at tail of 'str'
  *
  * @str: string to be manipulate
  * @ t : flag character
  * @return 0 means ok
  */
int trim_r(char* str,char t);

/**! From left to right cut substring starts with 't' 
  * @str : string to be maniputate
  * @ t  : flag
  * @return 0 means ok
  */
int cut_tail(char* str,char t);

/** split str into 2 string.one is name and the other is value 
 *
 * @str: the string to be split
 * @t  : flag char
 * @str1[][] must be 2 dimension
 * @return 0 means ok
 */
int split2(char* str,char t,char str1[][CONF_VALUE_LEN]);

#endif
